package com.yjs.ppjokedemo.bean;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.DiffUtil;

import com.bumptech.glide.Glide;

import java.util.Objects;

public class VideoProduct {

    private String id;
    private String name;
    private String videoUrl;
    private String imageUrl;

    public VideoProduct(String id, String name, String videoUrl, String imageUrl) {
        this.id = id;
        this.name = name;
        this.videoUrl = videoUrl;
        this.imageUrl = imageUrl;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVideoUrl() {
        return videoUrl;
    }

    public void setVideoUrl(String videoUrl) {
        this.videoUrl = videoUrl;
    }

    @Override
    public String toString() {
        return "VideoProduct{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", videoUrl='" + videoUrl + '\'' +
                ", imageUrl='" + imageUrl + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        VideoProduct that = (VideoProduct) o;
        return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(videoUrl, that.videoUrl) && Objects.equals(imageUrl, that.imageUrl);
    }


    public static DiffUtil.ItemCallback<VideoProduct> itemCallback = new DiffUtil.ItemCallback<VideoProduct>() {
        //判断id是否一致
        @Override
        public boolean areItemsTheSame(@NonNull VideoProduct oldItem, @NonNull VideoProduct newItem) {
            return oldItem.getId().equals(newItem.getId());
        }

        @Override
        public boolean areContentsTheSame(@NonNull VideoProduct oldItem, @NonNull VideoProduct newItem) {
            return oldItem.equals(newItem);
        }
    };

    //问题1
    @BindingAdapter("app:loadImage")
    public static void loadImage(ImageView imageView,String imageUrl){
        Glide.with(imageView.getContext())
                .load(imageUrl)
                .circleCrop()
                .into(imageView);
    }
}
